<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="pure-min.css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        include('config.php');
        $email = trim($_POST['email']);
        $cellulare = trim($_POST['cellulare']);
//echo $cellulare;
//echo $email;
//echo strlen($cellulare);
//echo strlen($email);
        if (strlen($cellulare) == 0 && strlen($email) == 0) {
//            print "<script type=\"text/javascript\">";
//            print "alert('Visualizzo tutte le registrazioni')";
//            print "</script>";
            $sql = "SELECT * FROM game order by cognome, nome, telefono";
        } else {
            $sql = "SELECT * FROM game where  (email='$email' or telefono='$cellulare') order by cognome, nome, telefono";
        }
//echo $sql;
        $result = mysql_query($sql);
//$row = mysql_fetch_array($result);
        $count = mysql_num_rows($result);
        if ($count > 0) {
//            print "<script type=\"text/javascript\">";
//            print "alert('Utente trovato')";
//            print "</script>";
//        while ($row = mysql_fetch_array($result)) {
//            echo "<p><h3>" . $row['telefono'] . "</h3>" . $row['email'] . "</p>";
//        }
            echo '<table class="pure-table pure-table-bordered">';
            echo '<thead>';
            echo '<tr>';
            //echo '<td>' . "ID" . '</td>';
            echo '<td valign="baseline">' . "CLIENTE" . '</td>';
            //echo '<td>' . "COGNOME" . '</td>';
            echo '<td valign="baseline">' . "EMAIL" . '</td>';
            echo '<td valign="baseline">' . "TEL." . '</td>';
            echo '<td valign="baseline">' . "IND." . '</td>';
            echo '<td valign="baseline">' . "FIORE" . '</td>';
            echo '<td valign="baseline">' . "MUSICA" . '</td>';
            echo '<td valign="baseline">' . "CARATTERE SPOSA" . '</td>';
            echo '<td valign="baseline">' . "LOCATION" . '</td>';
            echo '<td valign="baseline">' . "ABITO SPOSO" . '</td>';
            echo '<td valign="baseline">' . "ABITO SPOSA" . '</td>';
            echo '<td valign="baseline">' . "COLORI" . '</td>';
            echo '<td valign="baseline">' . "STILI" . '</td>';
            echo '<td valign="baseline">' . "NOTE" . '</td>';
            echo '<td valign="baseline">' . "" . '</td>';
            echo '</thead><tbody>';
            while ($row = mysql_fetch_array($result)) {
//        $id = $row['idgame'];
//        $email_trovata = $row['email'];
//        $telefono_trovato = $row['telefono'];
//        $nome_trovato = $row['nome'];
//        $cognome_trovato = $row['cognome'];
                //echo "<ul>\n";
                //echo "<li>" . "<a  href=\"search.php?id=$ID\">" . $FirstName . " " . $LastName . "</a></li>\n";
                //echo "<li>" . $nome_trovato . " " . $cognome_trovato . "</a></li>\n";
                //echo "</ul>";
                echo '<tr>';
                //echo '<td>' . $row['idgame'] . '</td>';
                echo '<td  valign="baseline">' . $row['nome'] . ' ' . $row['cognome'] . '</td>';
                //echo '<td>' . $row['cognome'] . '</td>';
                echo '<td  valign="baseline">' . "<a href='mailto:" . $row['email'] . "?subject=Benvenuto da RAMA S.r.l.'>" . $row['email'] . ' </td>';
                echo '<td valign="baseline">' . $row['telefono'] . '</td>';
                echo '<td valign="baseline">' . $row['indirizzo'] . '</td>';
                echo '<td valign="baseline">' . $row['livello1'] . '</td>';
                echo '<td valign="baseline">' . $row['livello2'] . '</td>';
                echo '<td valign="baseline">' . $row['livello3'] . '</td>';
                echo '<td valign="baseline">' . $row['livello4'] . '</td>';
                echo '<td valign="baseline">' . $row['livello5'] . '</td>';
                echo '<td valign="baseline">' . $row['livello6'] . '</td>';
                echo '<td valign="baseline">' . $row['livello7'] . '</td>';
                echo '<td valign="baseline">' . $row['livello8'] . '</td>';
                echo '<td valign="baseline">' . $row['note'] . '</td>';
                echo '<td valign="baseline">'
                . '<form action="edit.php" method="post">'
                . '<input type="hidden" name="idgame" value="' . $row['idgame'] . '"/>'
                . '<br />'
                . '<textarea name="note"  placeholder="Note e commenti..." value="' . $row['note'] . '"></textarea>'
                . '<br /><p>'
                . '<input type="submit" value="MODIFICA NOTE" class="pure-button pure-button-primary"/>'
                . '<br />'
                . '</form>'
                . '</td>';
                echo '</tr>';
            }
            echo '</tbody></table>';
        } else {
            print "<script type=\"text/javascript\">";
            print "alert('Nessun utente trovato')";
            print "</script>";
        }
        ?>
        <div>
            <style scoped>

                .pure-button-success,
                .pure-button-error,
                .pure-button-warning,
                .pure-button-secondary {
                    color: white;
                    border-radius: 4px;
                    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
                }

                .pure-button-success {
                    background: rgb(28, 184, 65); /* this is a green */
                }

                .pure-button-error {
                    background: rgb(202, 60, 60); /* this is a maroon */
                    font-size: 110%;
                }

                .pure-button-warning {
                    background: rgb(223, 117, 20); /* this is an orange */
                }
                .pure-button-secondary {
                    background: rgb(66, 184, 221); /* this is a light blue */
                }
            </style>
        </div>
        <div class="pure-g">
            <div class="pure-u-1-3">
                <form action="welcome.php" method="post">              
                    <input type="submit" value="RITORNA" class="pure-button pure-button-primary"/><br />
                </form>  
            </div>
            <div class="pure-u-1-3">                                                 
            </div>
            <div class="pure-u-1-3"> 
                <form action="logout.php" method="post">              
                    <input type="submit" value="ESCI" class="pure-button pure-button-error"/><br />
                </form>
            </div>
    </body>
</html>
